<?php
include '../data/masterbatch_dal.php';
include_once '../entity/masterbatch_entity.php';

class MasterbatchMng
{
    function update($masterbatchEntity)
    {
        $masterbatchDAL = new MasterbatchDAL();
        return $masterbatchDAL->update( $masterbatchEntity->id,
                                        $masterbatchEntity->rfqID,
                                        $masterbatchEntity->plasticType,
                                        $masterbatchEntity->meltFlow,
                                        $masterbatchEntity->customerResin,
                                        $masterbatchEntity->heatStability,
                                        $masterbatchEntity->weatherStability,
                                        $masterbatchEntity->lightFastness,
                                        $masterbatchEntity->additionalFunction1,
                                        $masterbatchEntity->additionalFunction2,
                                        $masterbatchEntity->contactRating,
                                        $masterbatchEntity->inTime,
                                        $masterbatchEntity->inUSer);
    }

    function get($id)
    {
        $where = "id = " . $id;
        $masterbatchDAL = new MasterbatchDAL();
        if ($result = $masterbatchDAL->get($where)) {
            $row = $result->fetch_assoc();
            $masterbatchEntity = new MasterbatchEntity();
            foreach ($row as $key => $value) {
                $masterbatchEntity->$key = $value;
            }
            return $masterbatchEntity;
        } else {
            return false;
        }
    }

    function getAll($start, $pageSize, $sortField, $sortDirection)
    {
        $orderBy = "ORDER BY " . $sortField . " " . $sortDirection . " LIMIT " . $start . ", " . ($pageSize * ($start + 1));
        $masterbatchDAL = new MaterialDAL();
        if ($result = $masterbatchDAL->getAll($orderBy)) {
            while ($row = $result->fetch_array()) {
                $masterbatchList[] = $row;
            }
            return $masterbatchList;
        } else {
            return false;
        }
    }

    function delete($id)
    {
        $masterbatchDAL = new MaterialDAL();
        return $masterbatchDAL->delete($id);
    }
}

?>
